﻿<!DOCTYPE html>
<html style="height: 100%">
<head>
    <meta charset="utf-8">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>

    <script src="http://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
    <style>
        * {
            font-size: 20px;
        }
        .showTable{
            width: 100%;
        }
        .showTable tr td{
            border-bottom: 1px silver solid;
        }
    </style>
</head>
<body style="height: 100%; margin: 0">
<p>公司名称:北京龙德时代技术服务有限公司</p>
<p id="device_mode">设备名称:多参数检测模块</p>
<p id="device_id">设备编号:100000</p>
<div id="div_appShow" style="display: none;">

</div>
<script type="text/javascript">
    function getQueryVariable(variable) {
        var query = window.location.search.substring(1);
        var vars = query.split("&");
        for (var i = 0; i < vars.length; i++) {
            var pair = vars[i].split("=");
            if (pair[0] == variable) {
                return pair[1];
            }
        }
        return (false);
    }

    var getURL = "http://localhost:9001/v1/customerService/getAllDeviceInfoByQrCode";
    var curInfo;
    $(document).ready(function () {
        let app = getQueryVariable("type");
        let qrcode = getQueryVariable("qrcode");
        if (app != null) {
            $("#device_id").html("设备编号:" + qrcode);
            let info = getDeviceInfo(getURL, {"qrCode": qrcode});
            debugger;
            if (info != null) {
                // 1 传感器 2 传输模块 3 电源模块 4 显示模块 5 二氧化碳模块
                let device_mode = "";
                if (info.type == 1) {
                    device_mode = "传感器模块";
                }
                if (info.type == 2) {
                    device_mode = "传输模块";
                }
                if (info.type == 3) {
                    device_mode = "电源模块";
                }
                if (info.type == 4) {
                    device_mode = "显示模块";
                }
                if (info.type == 5) {
                    device_mode = "二氧化碳模块";
                }
                $("#device_mode").text("设备名称:" + device_mode);
            }

            if (app == "app") {
                $("#div_appShow").show();

                let type = info.type;
                let coleData=info;
                let content = "<table class='showTable'>";
                //1 传感器 2 传输模块 3 电源模块 4 显示模块 5 二氧化碳模块
                content += "<tr><td>唯一编号</td><td>" + coleData.qrCode + "</td></tr>";

                if (type == 1) {
                    //content+="<tr><td>唯一编号</td><td>"+coleData.qrCode+"</td></tr>";
                    content += "<tr><td>主板</td><td>" + coleData.mainboard + "</td></tr>";
                    content += "<tr><td>氧气一氧化碳板</td><td>" + coleData.o2CoMainboard + "</td></tr>";
                    content += "<tr><td>ch4</td><td>" + coleData.ch4 + "</td></tr>";
                    content += "<tr><td>co</td><td>" + coleData.co + "</td></tr>";
                    content += "<tr><td>温湿度</td><td>" + coleData.th + "</td></tr>";
                    content += "<tr><td>氧气</td><td>" + coleData.o2 + "</td></tr>";
                    content += "<tr><td>烟雾</td><td>" + coleData.sm + "</td></tr>";
                } else if (type == 2) {//传输模块
                    //content+="<tr><td>外壳二维码</td><td>"+coleData.qrCode+"</td></tr>";
                    content += "<tr><td>光纤模块</td><td>" + coleData.opticalFiberMainboard + "</td></tr>";
                    content += "<tr><td>路由模块编号</td><td>" + coleData.mainboard + "</td></tr>";
                    content += "<tr><td>5V电源模块</td><td>" + coleData.battery5vMainboard + "</td></tr>";
                } else if (type == 3) {//电源模块
                    //content+="<tr><td>外壳二维码</td><td>"+coleData.qrCode+"</td></tr>";
                    content += "<tr><td>主板</td><td>" + coleData.mainboard + "</td></tr>";
                    content += "<tr><td>接线板</td><td>" + coleData.connectionMainboard + "</td></tr>";
                    content += "<tr><td>电池编号</td><td>" + coleData.batteryNumber + "</td></tr>";
                    content += "<tr><td>液晶板编号</td><td>" + coleData.lcNumber + "</td></tr>";
                } else if (type == 4) {//显示模块
                    //content+="<tr><td>外壳二维码</td><td>"+coleData.qrCode+"</td></tr>";
                    content += "<tr><td>主板编号</td><td>" + coleData.mainboard + "</td></tr>";
                    content += "<tr><td>模组编号</td><td>" + coleData.lcNumber + "</td></tr>";
                    content += "<tr><td>对讲模块编号</td><td>" + coleData.connectionMainboard + "</td></tr>";
                    content += "<tr><td>交换机模块编号</td><td>" + coleData.opticalFiberMainboard + "</td></tr>";
                    content += "<tr><td>5V模块编号</td><td>" + coleData.battery5vMainboard + "</td></tr>";
                } else if (type == 5) {//二氧化碳模块
                    //content+="<tr><td>外壳二维码</td><td>"+coleData.qrCode+"</td></tr>";
                    content += "<tr><td>二氧化碳板</td><td>" + coleData.mainboard + "</td></tr>";
                    content += "<tr><td>二氧化碳传感器</td><td>" + coleData.co2 + "</td></tr>";

                }
                content += "</table>";
                $("#div_appShow").append(content);
            }
        } else {
            alert("未指定类型！");
        }
    });


    function getDeviceInfo(postUrl, postData) {
        $.ajaxSettings.async = false;
        //this.filterMineByInfo(postData);
        var url = postUrl;
        var serverResultData;
        var jsonData = JSON.stringify(postData);
        $.ajax({
            //请求类型，这里为POST
            // xhrFields:{
            //     withCredentials:true
            // },
            type: 'POST', //你要请求的api的URL
            url: url, //是否使用缓存
            cache: false, //数据类型，这里我用的是json
            dataType: "json",
            contentType: "application/json;charset=utf-8",
            //必要的时候需要用JSON.stringify() 将JSON对象转换成字符串
            data: jsonData, //data: {key:value},
            //添加额外的请求头
            headers: {'Access-Control-Allow-Origin': '*', "token": window.localStorage.getItem("token")}, //请求成功的回调函数
            success: function (data) {
                //函数参数 "data" 为请求成功服务端返回的数据
                // if (data.code==500&&data.msg==401){
                //     //console.log("重新登录！");
                //     layer.msg("请重新登陆！",{icon:1,time:1000});
                //     //window.open("./login.html");
                //     //window.open("./login.html", "_blank", "resizable,scrollbars,status");
                //     top.location.href ="login.html"; //这种可以新页打开
                //     //window.parent.location.replace("login.html");//刷新父级页面; 这种可以新页打开
                // }
                // if(data.code==8001){
                //     layer.msg('无权限操作!',{icon:2,time:2000});
                // }
                serverResultData = data.data;
            }
        });
        $.ajaxSettings.async = true;
        return serverResultData;
    }
</script>
</body>
</html>
